package com.lagou.edu.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("进入验证");
        HttpSession session = request.getSession();
        String loginUser = (String)session.getAttribute("loginUser");
        if("admin".equals(loginUser)){
            System.out.println("登录成功");
            return true;
        }else{
            System.out.println("登录失败，返回首页");
            response.sendRedirect("/index.jsp?info=noauth");//返回根目录首页
        }
        return false;
    }
}
